package com.example.administrator.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private ListView listView;
    private String[] titles={"Java","PHP","c","javastrap","CSS"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    private void initView(){
        listView = findViewById(R.id.listview);
        listView.setAdapter(new MyAdapter());
    }
    private void initData(){

    }
    private void initEvent(){
       listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
           @Override
           public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
             Intent intent=new Intent(MainActivity.this,TwoActivity.class);
             startActivity(intent);
           }
       });
    }
    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Object getItem(int i) {
            return titles[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            view=View.inflate(MainActivity.this,R.layout.item_layout,null);
            TextView title=view.findViewById(R.id.item_title_tv);
            title.setText(titles[i]+"");
            return view;
        }
    }
}
